{% extends 'dashboard/base.html' %}

{% block body %}
<script type="text/javascript">

    $("#checkAll").change(function () {
        $("input:checkbox").prop('checked', $(this).prop("checked"));
    });
    $(document).ready(function() {
        $('.btn-danger').click(function(){
            if (confirm('Are you sure you want to delete this?')) {
                var vuln_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
                $.each($("input[name='del_vuln_id']:checked"), function(){
                    vuln_id.push($(this).val());
                });

                var json_vuln_id = vuln_id.join(", ");
                $.ajax({
                    type:'POST',
                    <!--contentType: 'application/json; charset=utf-8',-->
                    url:'{% url 'staticscanners:vuln_delete' %}',
                    data:{
                        vuln_id: json_vuln_id,
                        scan_id: $('input[name=scan_id]').val(),
                        csrfmiddlewaretoken:$('input[name=csrfmiddlewaretoken]').val()
                    },
                    sucess:function(){
                    }
                });
                setTimeout(function(){location.reload();},1000);
            }
        });

    });



$(document).on('click', '.confirm-delete', function(){
    return confirm('Are you sure you want to delete this?');
})


</script>


<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-body">
                {% if user.is_superuser == True or user.role.id == 2 %}
                <div class="float-right">
                    <button type="button" class="btn btn-danger btn-mini" onclick="">Delete Selected</button>
                </div>
                {% endif %}
                <br>
                <div class="d-md-flex align-items-center">
                    <h1 class="card-title">Vulnerability List</h1>
                </div>
                <br>
                <div class="row">
                    <div class="table-responsive">
                        <table id="data_table" class="table table-bordered data-table table-fixed" width="100%">
                            <thead>
                            <tr>
                                <th><label class="customcheckbox m-b-20">
                                    <input type="checkbox" id="mainCheckbox">
                                    <span class="checkmark"></span>
                                </label></th>
                                <th>Vulnerability</th>
                                <th>Filename</th>
                                <th>Risk</th>
                                <th>JIRA Ticket</th>
                                <th>Status</th>
                                {% if user.is_superuser == True or user.role.id == 2 %}
                                <th>False Positive</th>
                                <th>Delete</th>
                                <th>Mark</th>
                                {% endif %}
                            </tr>
                            </thead>
                            <tbody>{% for data in vuln_data %}
                            <tr data-target="#">
                                <td>
                                    <form>
                                        <label class="customcheckbox">
                                            <input type="checkbox" class="listCheckbox"
                                                   value="{{data.vuln_id}}"
                                                   name="del_vuln_id"
                                                   onClick="reload">
                                            <span class="checkmark"></span>
                                        </label>
                                    </form>
                                </td>
                                <td>
                                    <a href="{% url 'staticscanners:scan_details' %}?scan_id={{data.scan_id}}&vuln_id={{data.vuln_id}}&scanner={{ data.scanner }}">{{data.title}}</a>
                                </td>
                                <td>{{data.fileName}}</td>
                                <td><span
                                        class="badge badge-pill badge-{{data.severity_color}}">{{data.severity}}</span>
                                </td>
                                <td><a href="{{jira_url}}browse/{{data.jira_ticket}}" target="_blank">{{data.jira_ticket}}</a>
                                </td>

                                <td>
                                    <span class="badge badge-pill badge-primary">{{data.vuln_status}}</span>
                                    {% if data.note != None %}
                                    <i data-toggle="tooltip" data-placement="top" title
                                       data-original-title="{{data.note}}" class="fas fa-comment-alt"></i>
                                    {% endif %}
                                </td>
                                {% if user.is_superuser == True or user.role.id == 2 %}
                                {% if data.false_positive == 'No' %}
                                <td>
                                    <button class="btn btn-outline-info btn-mini" data-toggle="modal"
                                            data-target="#commentModal">Yes
                                    </button>
                                    <div class="modal fade" id="commentModal" tabindex="-1" role="dialog"
                                         aria-labelledby="commentModalLabel"
                                         aria-hidden="true">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="exampleModalLabel">Comment</h5>
                                                    <button type="button" class="close" data-dismiss="modal"
                                                            aria-label="Close">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                                <form method="POST" action="{% url 'staticscanners:vuln_mark' %}">{% csrf_token %}
                                                    <div class="modal-body">
                                                        <textarea class="form-control" name="note"
                                                                  id="message-text"></textarea>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-secondary"
                                                                data-dismiss="modal">Close
                                                        </button>
                                                        <input type="hidden" name="vuln_id" value="{{data.vuln_id}}">
                                                        <input type="hidden" name="false" value="Yes">
                                                        <input type="hidden" name="status" value="Open">
                                                        <input type="hidden" name="vuln_name" value="{{data.title}}">
                                                        <input type="hidden" name="scan_id" value="{{data.scan_id}}">
                                                        <input type="hidden" name="scanner" value="{{data.scanner}}">
                                                        <button class="btn btn-outline-info btn-mini">Save Note</button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                                {% endif %}
                                {% if data.false_positive == 'Yes' %}
                                <td>

                                    <button class="btn btn-outline-info btn-mini" data-toggle="modal"
                                            data-target="#commentNoModal">No
                                    </button>
                                    <div class="modal fade" id="commentNoModal" tabindex="-1" role="dialog" aria-labelledby="commentModalLabel"
                                         aria-hidden="true">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="exampleNoModalLabel">Comment</h5>
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                               <form method="POST" action="{% url 'staticscanners:vuln_mark' %}">{% csrf_token %}
                                                    <div class="modal-body">
                                                        <textarea class="form-control" name="note"  id="no-message-text"></textarea>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                        <input type="hidden" name="vuln_id" value="{{data.vuln_id}}">
                                                        <input type="hidden" name="false" value="No">
                                                        <input type="hidden" name="status" value="Open">
                                                        <input type="hidden" name="vuln_name" value="{{data.title}}">
                                                        <input type="hidden" name="scan_id" value="{{data.scan_id}}">
                                                        <input type="hidden" name="scanner" value="{{data.scanner}}">
                                                        <button class="btn btn-outline-info btn-mini">Save Note</button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                                {% endif %}
                                {% if data.false_positive == 'Duplicate' %}
                                <td>
                                    NA
                                </td>
                                {% endif %}
                                <td class="confirm-delete">
                                    <div>
                                        <form action="{% url 'staticscanners:vuln_delete' %}" method="POST"
                                              class="form-horizontal">
                                            {% csrf_token %}
                                            <input type="hidden" name="vuln_id" value="{{data.vuln_id}}">
                                            <input type="hidden" name="scan_id" value="{{data.scan_id}}">
                                            <input type="hidden" name="scanner" value="{{ data.scanner }}">
                                            <button class="btn btn-warning btn-mini"><i class="fas fa-trash"></i>
                                            </button>
                                        </form>
                                    </div>
                                </td>
                                {% if data.vuln_status == 'Open' %}
                                <td>
                                    <button class="btn btn-outline-info btn-mini" data-toggle="modal"
                                            data-target="#commentCloseModal">Close
                                    </button>
                                    <div class="modal fade" id="commentCloseModal" tabindex="-1" role="dialog" aria-labelledby="ClosecommentModalLabel"
                                         aria-hidden="true">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="CloseModalLabel">Comment</h5>
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                                <form method="POST" action="{% url 'staticscanners:vuln_mark' %}">{% csrf_token %}
                                                    <div class="modal-body">
                                                        <textarea class="form-control" name="note"  id="close-message-text"></textarea>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                       <input type="hidden" name="vuln_id" value="{{data.vuln_id}}">
                                                        <input type="hidden" name="false" value="No">
                                                        <input type="hidden" name="status" value="Closed">
                                                        <input type="hidden" name="vuln_name" value="{{data.title}}">
                                                        <input type="hidden" name="scan_id" value="{{data.scan_id}}">
                                                        <input type="hidden" name="scanner" value="{{data.scanner}}">
                                                        <button class="btn btn-outline-info btn-mini">Save Note</button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                                {% endif %}
                                {% if data.vuln_status == 'Closed' %}
                                <td>
                                    <button class="btn btn-outline-info btn-mini" data-toggle="modal"
                                            data-target="#commentOpenModal">Open
                                    </button>
                                    <div class="modal fade" id="commentOpenModal" tabindex="-1" role="dialog" aria-labelledby="ClosecommentModalLabel"
                                         aria-hidden="true">
                                        <div class="modal-dialog" role="document">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="OpenModalLabel">Comment</h5>
                                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                        <span aria-hidden="true">&times;</span>
                                                    </button>
                                                </div>
                                                <form method="POST" action="{% url 'staticscanners:vuln_mark' %}">{% csrf_token %}
                                                    <div class="modal-body">
                                                        <textarea class="form-control" name="note"  id="open-message-text"></textarea>
                                                    </div>
                                                    <div class="modal-footer">
                                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                        <input type="hidden" name="vuln_id" value="{{data.vuln_id}}">
                                                        <input type="hidden" name="false" value="No">
                                                        <input type="hidden" name="status" value="Open">
                                                        <input type="hidden" name="vuln_name" value="{{data.title}}">
                                                        <input type="hidden" name="scan_id" value="{{data.scan_id}}">
                                                        <input type="hidden" name="scanner" value="{{data.scanner}}">
                                                        <button class="btn btn-outline-info btn-mini">Save Note</button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                                {% endif %}
                                {% if data.vuln_status == 'Duplicate' %}
                                <td>
                                    NA
                                </td>
                                {% endif %}
                                {% endif %}
                            </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}
